package net.jgrm.order.dto;

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import lombok.Data;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * 订单导出DTO类，用于Excel导出
 */
@Data
public class OrderExportDTO {

    @ExcelProperty("订单编号")
    @ColumnWidth(20)
    private String orderNo;

    @ExcelProperty("用户ID")
    @ColumnWidth(10)
    private Long userId;

    @ExcelProperty("总金额")
    @ColumnWidth(15)
    private BigDecimal totalAmount;

    @ExcelProperty("订单状态")
    @ColumnWidth(10)
    private String status;

    @ExcelProperty("收货人姓名")
    @ColumnWidth(15)
    private String receiverName;

    @ExcelProperty("收货人手机号")
    @ColumnWidth(15)
    private String receiverPhone;

    @ExcelProperty("收货地址")
    @ColumnWidth(30)
    private String receiverAddress;

    @ExcelProperty("交易流水号")
    @ColumnWidth(25)
    private String transactionId;

    @ExcelProperty("支付时间")
    @ColumnWidth(20)
    private String paymentTime;

    @ExcelProperty("创建时间")
    @ColumnWidth(20)
    private String createTime;

    /**
     * 格式化LocalDateTime为字符串
     */
    public static String formatDateTime(LocalDateTime dateTime) {
        if (dateTime == null) {
            return "";
        }
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return dateTime.format(formatter);
    }

    /**
     * 获取订单状态的中文描述
     */
    public static String getStatusDesc(Integer status) {
        if (status == null) {
            return "未知";
        }
        switch (status) {
            case 0:
                return "待支付";
            case 1:
                return "已支付";
            case 2:
                return "已取消";
            default:
                return "未知";
        }
    }
}